<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category Update.php
 * @Depiction
 * @Author hwy
 * @Date 2021/5/25  15:33
 * +--------------------------------------------------------+
 */

namespace App\Http\Requests\Admin;


use App\Http\Requests\BaseRequestsPost;
use App\Rules\AlphaNumRule;

class Update extends BaseRequestsPost
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name'     => ['required', 'unique:admins,name,' . $this->route('id') , new AlphaNumRule()],
            'role_id'  => 'required',
        ];

        if ($this->get('password')) {
            $rules['password'] = 'required|between:6,18';
        }

        return $rules;
    }

    /**
     * 定义字段名中文
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'name'     => '标签名称',
            'password' => '密码',
            'role_id'  => '角色',
        ];
    }

    public function messages()
    {
        return [
            'name.required'    => '用户名不能为空！',
            'name.unique'      => '用户名已存在！',
            'password.between' => '密码长度在6-18个字符之间！',
            'role_id.required' => '角色不能为空！',
        ];
    }

}